package com.steel.yfmall.cloud.assistant.listener;

import com.alibaba.fastjson.JSON;
import com.steel.yfmall.cloud.assistant.api.stock.CqUserPushServiceAPI;
import com.steel.yfmall.cloud.assistant.bean.param.APIParamUserPushBean;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @program: UserBaseListener
 * @author: liuzhijun
 * @date: 2021-04-20 20:51
 **/
@Slf4j
@Component
public class UserBaseListener {

    @Resource
    private CqUserPushServiceAPI cqUserPushServiceAPI;

    /**
     * 推送用户子账户到苍穹
     *
     * @param onMsgText
     * @return void
     * @author liuzhijun
     * @date 2021/4/21 08:55
     */
    @JmsListener(destination = "user_base_push")
    public void pushUserInfotoCq(String onMsgText) {
        try {
            if (log.isDebugEnabled()) {
                log.info("user_base_push: " + onMsgText);
            }
            if (StringUtils.isBlank(onMsgText)) {
                log.error("推送推送用户子账户信息:参数为空");
                return;
            }
            APIParamUserPushBean apiParamUserBaseBean = JSON.parseObject(onMsgText, APIParamUserPushBean.class);
            cqUserPushServiceAPI.pushUserToCq(apiParamUserBaseBean);
        } catch (Exception e) {
            log.error(onMsgText + "推送推送用户子账户信息失败", e);
        }
    }

}
